{extend name="$base" /}
{block name="resources"}
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.all.common.js"></script>
<style>
	#editor{width: 100%;}
</style>
{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span class="required">*</span>协议标题：</dt>
		<dd>
			<input id="title" type="text" class="input-common" value="{$info['title']}"/>
			<span class="error">请输入标题</span>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>协议内容：</dt>
		<dd>
			<script id="editor" type="text/plain">{$info['content']}</script>
			<span class="error">请输入协议内容</span>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd>
			<button class="btn-common btn-big" onclick="save()" >保存</button>
			<button class="btn-common-cancle btn-big" onclick="javascript:history.back(-1);" >返回</button>
		</dd>
	</dl>
</div>
<script>
var flag = false;//防止重复提交
var ue = UE.getEditor('editor',{ "initialFrameHeight" : 450, 'wordCount' : false});
//验证数据
function verification(title,content){
	if(title.length == 0){
		$("#title").next(".error").show();
		return false;
	}else{
		$(".error").hide();
	}
	if(content.length == 0){
		$("#editor").next(".error").show();
		return false;
	}else{
		$(".error").hide();
	}
	if(getLength(content) >= 20000){
		showTip("注册协议字节不应该超过2500","error");
		return false;
	}
	return true;
}

function save(){
	var title = $("#title").val();
	var content = ue.getContent().replace(/\n*/g, "").replace(/\r*/g, "");
	if(verification(title,content)){
		//防止重复提交
		if(!flag){
			flag = true;
			$.ajax({
				type : "post",
				url : "{:__URL('ADMIN_MAIN/member/registrationAgreement')}",
				data : {
					'title' : title,
					'content' : content,
				},
				success : function(data){
					if(data['code'] > 0){
						showTip("发布成功","success");
						location.href = "{:__URL('ADMIN_MAIN/member/registrationAgreement')}";
					}else{
						showTip("发布失败","error");
					}
					flag = false;
				}
			})
		}
	}
}

function getLength(str) 
{
    return str.replace(/[^\x00-\xff]/g,"aa").length;
}; 
</script>
{/block}